package com.trz.cqrs.core.async;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.trz.cqrs.core.configurer.Constants.EXECUTOR;

@Slf4j
@Component
class AsyncMonitor {

    @Resource(name = EXECUTOR)
    private ThreadPoolTaskExecutor taskExecutor;

    @Scheduled(fixedRate = 60000L)
    public void monitor() {
        val e = taskExecutor.getThreadPoolExecutor();
        log.info("Pool => Core: {} Active: {} Current: {} Maximum: {}, Queue: {}, Task => Total: {} Completed: {}",
                e.getCorePoolSize(), e.getActiveCount(), e.getPoolSize(), e.getMaximumPoolSize(),
                e.getQueue().size(), e.getTaskCount(), e.getCompletedTaskCount()
        );
    }

}
